package com.source.multithread.atomicc;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;

/**
 * @Author wengqy
 * @Date 2020/12/25
 */
public class AtomicRefernceDemo {
    public static void main(String[] args) {
        User aa = new User("aa", 11);
        User bb = new User("bb", 22);

        AtomicReference<User> atomicReference  = new AtomicReference();
        atomicReference.set(aa);
        System.out.println(atomicReference.compareAndSet(aa, bb));
        System.out.println(atomicReference.get().toString());

        System.out.println(atomicReference.compareAndSet(aa, bb));
        System.out.println(atomicReference.get().toString());

    }
}


class User{
    String username;
    int age;
    public User(String username, int age) {
        this.username = username;
        this.age = age;
    }
    @Override
    public String toString() {
        return "User{" +
                "username='" + username + '\'' +
                ", age=" + age +
                '}';
    }
}
